﻿using System;
using System.Data;
using System.Deployment.Application;
using System.Threading;
using System.Windows.Forms;
using ClassLib.Classes.Connection;
using DevExpress.XtraEditors;
using DevExpress.XtraSplashScreen;
using ISumen;
using MySql.Data.MySqlClient;
using Sumen.Business;
using Sumen.Business.Model;
using Sumen.Business.Model.Presenter.Report;
using Sumen.Business.Model.Presenter.Sys;
using Sumen_Stock.LookAndFeel.Admin;
using Sumen_Stock.LookAndFeel.Category;
using DevExpress.Utils;
using Sumen_Stock.LookAndFeel.Inventory;
using Sumen_Stock.LookAndFeel.Entities;
using Sumen_Stock.LookAndFeel.Report;
using Sumen_Stock.LookAndFeel.Sumen_System;
using ClassLib.Froms.Connection;
using ClassLib.Classes.Common;
using Sumen_Stock.LookAndFeel.Help;
using Sumen_Stock.LookAndFeel.Sales;

namespace Sumen_Stock
{
    public partial class Main : DevExpress.XtraBars.Ribbon.RibbonForm
    {

        #region Category
        Frm_Product_Color frm_product_color;
        Frm_Product_Size frm_size;
        Frm_Product_Provider frm_provider;
        Frm_Product_Category frm_category;
        Frm_Product_Type frm_product_type;
        Frm_Position_X frm_x;
        Frm_Position_Y frm_y;
        private Frm_Position_Range _frmPositionRange;
        Frm_Discount frm_discount;
        Frm_Customer_Type customer_type;
        Frm_Stock frm_stock;
        Frm_District frm_district;
        Frm_Province frm_province;
        #endregion

        #region Kho
        Frm_Check_Inventory frm_check_inventory;
        Frm_General_Inventory frm_general_inventory;
        Frm_General_Inward_Outward frm_in_out_inventory;
        Frm_History_Product frm_history_product;
        Frm_Inventory frm_inventory;
        Frm_Stock_Inward frm_inward;
        Frm_Stock_Outward frm_outward;
        #endregion

        #region Entities
        Frm_Customer frm_customer;
        Frm_Employee frm_emp;
        Frm_Product frm_product;
        #endregion

        #region System
        Frm_Parameters frm_parameters;
        Frm_History_System frm_history_system;
        #endregion

        #region Report
        #endregion

        #region Help
        Frm_Website frm_web;
        Frm_Information frm_information;
        #endregion

        WaitDialogForm waitDialogForm;

        public Main()
        {
            InitializeComponent();
            InitSkinGallery();

            Version currentVersion = System.Reflection.Assembly.GetExecutingAssembly()
               .GetName().Version;

            // Kiểm tra version khi build bằng ClickOnce
            if (ApplicationDeployment.IsNetworkDeployed)
            {
                currentVersion = ApplicationDeployment.CurrentDeployment.CurrentVersion;
            }
            bbStaticVersion.Caption = string.Format("Phiên bản: {0}", currentVersion.ToString());

            ClsPublic.GetListParameters();

            //create event catch msg from socket server
            ClsPublic.StartSocket();

#if (DEBUG)

#else
               if (ClsPublic.Writelog == "1")
            {
                SysLogPresenter log = new SysLogPresenter();
                log.Add(FromCode.FrmLogin, EnumFormStatus.View, ClsPublic.Emp.Emp_Username, "");
            }    
#endif


        }



        private void Main_Load(object sender, EventArgs e)
        {

        }

        #region Sumen system event

        private void bbPermission_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {

        }

        private void bbPermissionGroup_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {

        }

        private void bbCauHinhServer_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            SplashScreenManager.ShowForm(typeof(WaitForm1));
            FrmCauHinhCSDL frm_cauhinh = new FrmCauHinhCSDL();
            frm_cauhinh.ShowDialog();
            SplashScreenManager.CloseForm();
        }

        private void bbThamSo_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            SplashScreenManager.ShowForm(typeof(WaitForm1));
            // waitDialogForm = new DevExpress.Utils.WaitDialogForm("Đang nạp dữ liệu ...", "Vui lòng chờ giây lát !");
            if (frm_parameters == null || frm_parameters.IsDisposed)
            {
                frm_parameters = new Frm_Parameters();
                frm_parameters.MdiParent = this;
                frm_parameters.Show();
            }
            else
            {
                frm_parameters.Activate();
            }
            SplashScreenManager.CloseForm();
            //SplashScreenManager.CloseForm();
        }

        private Frm_Log_Error _frmLogError;
        private void bbError_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            SplashScreenManager.ShowForm(typeof(WaitForm1));
            if (_frmLogError == null || _frmLogError.IsDisposed)
            {
                _frmLogError = new Frm_Log_Error();
                _frmLogError.MdiParent = this;
                _frmLogError.Show();
            }
            else
            {
                _frmLogError.MdiParent = this;
                _frmLogError.Activate();
            }
            SplashScreenManager.CloseForm();
        }

        private void bbTaiKhoan_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {

        }

        private void bbDoiMatKhau_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            SplashScreenManager.ShowForm(typeof(WaitForm1));
            Frm_Change_Password frm_change_pass = new Frm_Change_Password();
            frm_change_pass.ShowDialog();
            SplashScreenManager.CloseForm();
        }

        private void bbNhatKy_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            //waitDialogForm = new DevExpress.Utils.WaitDialogForm("Đang nạp dữ liệu ...", "Vui lòng chờ giây lát !");
            SplashScreenManager.ShowForm(typeof(WaitForm1));
            if (frm_history_system == null || frm_history_system.IsDisposed)
            {
                frm_history_system = new Frm_History_System();
                frm_history_system.MdiParent = this;
                frm_history_system.Show();
            }
            else
            {
                frm_history_system.Activate();
            } SplashScreenManager.CloseForm();
        }

        private void bbSaoLuu_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Frm_BackUp frm_backup = new Frm_BackUp();
            frm_backup.ShowDialog();
        }

        private void bbPhucHoi_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Frm_Restore frm_restore = new Frm_Restore();
            frm_restore.ShowDialog();
        }

        private void iExit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            this.Close();
        }

        private void Main_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (ClsBaoLoi.XacNhan("Bạn có chắc thoát chương trình?"))
            {
                e.Cancel = false;
            }
            else
            {
                e.Cancel = true;
            }

        }

        private void Main_FormClosed(object sender, FormClosedEventArgs e)
        {

            Application.Exit();
        }

        #endregion

        #region Danh muc event

        private void barButtonItem2_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            SplashScreenManager.ShowForm(typeof(WaitForm1));
            //waitDialogForm = new DevExpress.Utils.WaitDialogForm("Đang nạp dữ liệu ...", "Vui lòng chờ giây lát !");
            if (_frmPositionRange == null || _frmPositionRange.IsDisposed)
            {
                _frmPositionRange = new Frm_Position_Range();
                _frmPositionRange.MdiParent = this;
                _frmPositionRange.Show();
            }
            else
            {
                _frmPositionRange.Activate();
            } SplashScreenManager.CloseForm();
        }

        private void bbMau_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            SplashScreenManager.ShowForm(typeof(WaitForm1));
            //waitDialogForm = new DevExpress.Utils.WaitDialogForm("Đang nạp dữ liệu ...", "Vui lòng chờ giây lát !");
            if (frm_product_color == null || frm_product_color.IsDisposed)
            {
                frm_product_color = new Frm_Product_Color();
                frm_product_color.MdiParent = this;
                frm_product_color.Show();
            }
            else
            {
                frm_product_color.Activate();
            } SplashScreenManager.CloseForm();
        }

        private void bbSize_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            SplashScreenManager.ShowForm(typeof(WaitForm1));
            //waitDialogForm = new DevExpress.Utils.WaitDialogForm("Đang nạp dữ liệu ...", "Vui lòng chờ giây lát !");
            if (frm_size == null || frm_size.IsDisposed)
            {
                frm_size = new Frm_Product_Size();
                frm_size.MdiParent = this;
                frm_size.Show();
            }
            else
            {
                frm_size.Activate();
            } SplashScreenManager.CloseForm();
        }

        private void bbNhaCungCap_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            SplashScreenManager.ShowForm(typeof(WaitForm1));
            //waitDialogForm = new DevExpress.Utils.WaitDialogForm("Đang nạp dữ liệu ...", "Vui lòng chờ giây lát !");
            if (frm_provider == null || frm_provider.IsDisposed)
            {
                frm_provider = new Frm_Product_Provider();
                frm_provider.MdiParent = this;
                frm_provider.Show();
            }
            else
            {
                frm_provider.Activate();
            } SplashScreenManager.CloseForm();
        }

        private void bbDanhMuc_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            SplashScreenManager.ShowForm(typeof(WaitForm1));
            //waitDialogForm = new DevExpress.Utils.WaitDialogForm("Đang nạp dữ liệu ...", "Vui lòng chờ giây lát !");
            if (frm_category == null || frm_category.IsDisposed)
            {
                frm_category = new Frm_Product_Category();
                frm_category.MdiParent = this;
                frm_category.Show();
            }
            else
            {
                frm_category.Activate();
            }
            SplashScreenManager.CloseForm();
        }

        private void bbChungLoai_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            SplashScreenManager.ShowForm(typeof(WaitForm1));
            // waitDialogForm = new DevExpress.Utils.WaitDialogForm("Đang nạp dữ liệu ...", "Vui lòng chờ giây lát !");
            if (frm_product_type == null || frm_product_type.IsDisposed)
            {
                frm_product_type = new Frm_Product_Type();
                frm_product_type.MdiParent = this;
                frm_product_type.Show();
            }
            else
            {
                frm_product_type.Activate();
            } SplashScreenManager.CloseForm();
        }

        private void bbThanhPho_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            SplashScreenManager.ShowForm(typeof(WaitForm1));
            //waitDialogForm = new DevExpress.Utils.WaitDialogForm("Đang nạp dữ liệu ...", "Vui lòng chờ giây lát !");
            if (frm_province == null || frm_province.IsDisposed)
            {
                frm_province = new Frm_Province();
                frm_province.MdiParent = this;
                frm_province.Show();
            }
            else
            {
                frm_province.Activate();
            } SplashScreenManager.CloseForm();
        }

        private void bbQuan_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            SplashScreenManager.ShowForm(typeof(WaitForm1));
            //waitDialogForm = new DevExpress.Utils.WaitDialogForm("Đang nạp dữ liệu ...", "Vui lòng chờ giây lát !");
            if (frm_district == null || frm_district.IsDisposed)
            {
                frm_district = new Frm_District();
                frm_district.MdiParent = this;
                frm_district.Show();
            }
            else
            {
                frm_district.Activate();
            } SplashScreenManager.CloseForm();
        }

        private void bbHangDoc_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            SplashScreenManager.ShowForm(typeof(WaitForm1));
            //waitDialogForm = new DevExpress.Utils.WaitDialogForm("Đang nạp dữ liệu ...", "Vui lòng chờ giây lát !");
            if (frm_y == null || frm_y.IsDisposed)
            {
                frm_y = new Frm_Position_Y();
                frm_y.MdiParent = this;
                frm_y.Show();
            }
            else
            {
                frm_y.Activate();
            } SplashScreenManager.CloseForm();
        }

        private void bbHangNgang_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            SplashScreenManager.ShowForm(typeof(WaitForm1));
            //waitDialogForm = new DevExpress.Utils.WaitDialogForm("Đang nạp dữ liệu ...", "Vui lòng chờ giây lát !");
            if (frm_x == null || frm_x.IsDisposed)
            {
                frm_x = new Frm_Position_X();
                frm_x.MdiParent = this;
                frm_x.Show();
            }
            else
            {
                frm_x.Activate();
            } SplashScreenManager.CloseForm();
        }

        private void bbLoaiKhachHang_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            SplashScreenManager.ShowForm(typeof(WaitForm1));
            //waitDialogForm = new DevExpress.Utils.WaitDialogForm("Đang nạp dữ liệu ...", "Vui lòng chờ giây lát !");
            if (customer_type == null || customer_type.IsDisposed)
            {
                customer_type = new Frm_Customer_Type();
                customer_type.MdiParent = this;
                customer_type.Show();
            }
            else
            {
                customer_type.Activate();
            } SplashScreenManager.CloseForm();
        }

        private void bbGiamGia_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            SplashScreenManager.ShowForm(typeof(WaitForm1));
            // waitDialogForm = new DevExpress.Utils.WaitDialogForm("Đang nạp dữ liệu ...", "Vui lòng chờ giây lát !");
            if (frm_discount == null || frm_discount.IsDisposed)
            {
                frm_discount = new Frm_Discount();
                frm_discount.MdiParent = this;
                frm_discount.Show();
            }
            else
            {
                frm_discount.Activate();
            } SplashScreenManager.CloseForm();
        }

        private void bbkho_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            SplashScreenManager.ShowForm(typeof(WaitForm1));
            //waitDialogForm = new DevExpress.Utils.WaitDialogForm("Đang nạp dữ liệu ...", "Vui lòng chờ giây lát !");
            if (frm_stock == null || frm_stock.IsDisposed)
            {
                frm_stock = new Frm_Stock();
                frm_stock.MdiParent = this;
                frm_stock.Show();
            }
            else
            {
                frm_stock.Activate();
            } SplashScreenManager.CloseForm();
        }
        #endregion

        #region Inventory event

        private void bbNhapKho_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            SplashScreenManager.ShowForm(typeof(WaitForm1));
            //waitDialogForm = new DevExpress.Utils.WaitDialogForm("Đang nạp dữ liệu ...", "Vui lòng chờ giây lát !");
            if (frm_inward == null || frm_inward.IsDisposed)
            {
                frm_inward = new Frm_Stock_Inward();
                frm_inward.MdiParent = this;
                frm_inward.Show();
            }
            else
            {
                frm_inward.Activate();
            } SplashScreenManager.CloseForm();
        }

        private void bbXuatKho_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            SplashScreenManager.ShowForm(typeof(WaitForm1));
            //waitDialogForm = new DevExpress.Utils.WaitDialogForm("Đang nạp dữ liệu ...", "Vui lòng chờ giây lát !");
            if (frm_outward == null || frm_outward.IsDisposed)
            {
                frm_outward = new Frm_Stock_Outward();
                frm_outward.MdiParent = this;
                frm_outward.Show();
            }
            else
            {
                frm_outward.Activate();
            } SplashScreenManager.CloseForm();
        }

        private void bbTonKho_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            SplashScreenManager.ShowForm(typeof(WaitForm1));
            //waitDialogForm = new DevExpress.Utils.WaitDialogForm("Đang nạp dữ liệu ...", "Vui lòng chờ giây lát !");
            if (frm_inventory == null || frm_inventory.IsDisposed)
            {
                frm_inventory = new Frm_Inventory();
                frm_inventory.MdiParent = this;
                frm_inventory.Show();
            }
            else
            {
                frm_inventory.Activate();
            } SplashScreenManager.CloseForm();
        }

        private void bbTongHopTonKho_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            SplashScreenManager.ShowForm(typeof(WaitForm1));
            //waitDialogForm = new DevExpress.Utils.WaitDialogForm("Đang nạp dữ liệu ...", "Vui lòng chờ giây lát !");
            if (frm_general_inventory == null || frm_general_inventory.IsDisposed)
            {
                frm_general_inventory = new Frm_General_Inventory();
                frm_general_inventory.MdiParent = this;
                frm_general_inventory.Show();
            }
            else
            {
                frm_general_inventory.Activate();
            } SplashScreenManager.CloseForm();
        }

        private void bbKiemKe_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            SplashScreenManager.ShowForm(typeof(WaitForm1));
            //waitDialogForm = new DevExpress.Utils.WaitDialogForm("Đang nạp dữ liệu ...", "Vui lòng chờ giây lát !");
            if (frm_check_inventory == null || frm_check_inventory.IsDisposed)
            {
                frm_check_inventory = new Frm_Check_Inventory();
                frm_check_inventory.MdiParent = this;
                frm_check_inventory.Show();
            }
            else
            {
                frm_check_inventory.Activate();
            } SplashScreenManager.CloseForm();
        }

        private void bbLichSuHangHoa_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            SplashScreenManager.ShowForm(typeof(WaitForm1));
            //waitDialogForm = new DevExpress.Utils.WaitDialogForm("Đang nạp dữ liệu ...", "Vui lòng chờ giây lát !");
            if (frm_history_product == null || frm_history_product.IsDisposed)
            {
                frm_history_product = new Frm_History_Product();
                frm_history_product.MdiParent = this;
                frm_history_product.Show();
            }
            else
            {
                frm_history_product.Activate();
            } SplashScreenManager.CloseForm();
        }

        private void bbTongHopXN_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            SplashScreenManager.ShowForm(typeof(WaitForm1));
            //waitDialogForm = new DevExpress.Utils.WaitDialogForm("Đang nạp dữ liệu ...", "Vui lòng chờ giây lát !");
            if (frm_in_out_inventory == null || frm_in_out_inventory.IsDisposed)
            {
                frm_in_out_inventory = new Frm_General_Inward_Outward();
                frm_in_out_inventory.MdiParent = this;
                frm_in_out_inventory.Show();
            }
            else
            {
                frm_in_out_inventory.Activate();
            } SplashScreenManager.CloseForm();
        }

        private void bbTraCuuHoSo_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {

        }


        #endregion

        #region Entity event click

        private void bbNhanVien_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            SplashScreenManager.ShowForm(typeof(WaitForm1));
            if (frm_emp == null || frm_emp.IsDisposed)
            {
                frm_emp = new Frm_Employee();
                frm_emp.MdiParent = this;
                frm_emp.Show();
            }
            else
            {
                frm_emp.Activate();
            }
            SplashScreenManager.CloseForm();
        }

        private void bbKhachHang_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            SplashScreenManager.ShowForm(typeof(WaitForm1));
            if (frm_customer == null || frm_customer.IsDisposed)
            {
                frm_customer = new Frm_Customer();
                frm_customer.MdiParent = this;
                frm_customer.Show();
            }
            else
            {
                frm_customer.Activate();
            }
            SplashScreenManager.CloseForm();
        }

        private void bbSanPham_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            SplashScreenManager.ShowForm(typeof(WaitForm1));
            //waitDialogForm = new DevExpress.Utils.WaitDialogForm("Đang nạp dữ liệu ...", "Vui lòng chờ giây lát !");
            if (frm_product == null || frm_product.IsDisposed)
            {
                frm_product = new Frm_Product();
                frm_product.MdiParent = this;
                frm_product.Show();
            }
            else
            {
                frm_product.Activate();
            }
            SplashScreenManager.CloseForm();
        }

        #endregion

        #region Help event

        private void bbWebsite_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            SplashScreenManager.ShowForm(typeof(WaitForm1));
            //waitDialogForm = new DevExpress.Utils.WaitDialogForm("Đang nạp dữ liệu ...", "Vui lòng chờ giây lát !");
            if (frm_web == null || frm_web.IsDisposed)
            {
                frm_web = new Frm_Website();
                frm_web.MdiParent = this;
                frm_web.Show();
            }
            else
            {
                frm_web.Activate();
            }
            SplashScreenManager.CloseForm();
        }

        #endregion

        #region Report event click

        private ReportInwardOutward _reportInwardOutward;
        private void bbTkLoiNhuan_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            SplashScreenManager.ShowForm(typeof(WaitForm1));
            if (_reportInwardOutward == null || _reportInwardOutward.IsDisposed)
            {
                _reportInwardOutward = new ReportInwardOutward();
                _reportInwardOutward.MdiParent = this;
                _reportInwardOutward.Show();
            }
            else
            {
                _reportInwardOutward.Activate();
            }
            SplashScreenManager.CloseForm();
        }

        #endregion

        #region Bán hàng (sales)

        private Frm_Sales_Sale _frm_Sales_Sale;
        private void bbBanHang_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            SplashScreenManager.ShowForm(typeof(WaitForm1));
            if (_frm_Sales_Sale == null || _frm_Sales_Sale.IsDisposed)
            {
                _frm_Sales_Sale = new Frm_Sales_Sale();
                _frm_Sales_Sale.MdiParent = this;
                _frm_Sales_Sale.Show();
            }
            else
            {
                _frm_Sales_Sale.MdiParent = this;
                _frm_Sales_Sale.Activate();
            }
            SplashScreenManager.CloseForm();
        }

        private Frm_Sales_Return _frm_Sales_Return;
        private void bbTraHang_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            SplashScreenManager.ShowForm(typeof(WaitForm1));
            if (_frm_Sales_Return == null || _frm_Sales_Return.IsDisposed)
            {
                _frm_Sales_Return = new Frm_Sales_Return();
                _frm_Sales_Return.MdiParent = this;
                _frm_Sales_Return.Show();
            }
            else
            {
                _frm_Sales_Return.Activate();
            }
            SplashScreenManager.CloseForm();
        }

        private Frm_Sales_Change_Product _frm_Sale_Change_Product;
        private void bbDoiHang_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            SplashScreenManager.ShowForm(typeof(WaitForm1));
            if (_frm_Sale_Change_Product == null || _frm_Sale_Change_Product.IsDisposed)
            {
                _frm_Sale_Change_Product = new Frm_Sales_Change_Product();
                _frm_Sale_Change_Product.MdiParent = this;
                _frm_Sale_Change_Product.Show();
            }
            else
            {
                _frm_Sale_Change_Product.Activate();
            }
            SplashScreenManager.CloseForm();
        }

        private Frm_Sales_Orders _frm_Sales_Orders;
        private void bbDatHang_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            SplashScreenManager.ShowForm(typeof(WaitForm1));
            if (_frm_Sales_Orders == null || _frm_Sales_Orders.IsDisposed)
            {
                _frm_Sales_Orders = new Frm_Sales_Orders();
                _frm_Sales_Orders.MdiParent = this;
                _frm_Sales_Orders.Show();
            }
            else
            {
                _frm_Sales_Orders.Activate();
            }
            SplashScreenManager.CloseForm();
        }

        private Frm_Sales_OutOfStock _frmSalesOutOfStock;
        private void bbDatHangTamHet_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            SplashScreenManager.ShowForm(typeof(WaitForm1));
            if (_frmSalesOutOfStock == null || _frmSalesOutOfStock.IsDisposed)
            {
                _frmSalesOutOfStock = new Frm_Sales_OutOfStock();
                _frmSalesOutOfStock.MdiParent = this;
                _frmSalesOutOfStock.Show();
            }
            else
            {
                _frmSalesOutOfStock.Activate();
            }
            SplashScreenManager.CloseForm();
        }


        #endregion

        #region Admin

        private Frm_Manager_Orders _frmManagerOrders;
        private void bbQuanLyHoaDon_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            SplashScreenManager.ShowForm(typeof(WaitForm1));
            if (_frmManagerOrders == null || _frmManagerOrders.IsDisposed)
            {
                _frmManagerOrders = new Frm_Manager_Orders();
                _frmManagerOrders.MdiParent = this;
                _frmManagerOrders.Show();
            }
            else
            {
                _frmManagerOrders.Activate();
            }
            SplashScreenManager.CloseForm();
        }

        private Frm_User _frmUser;
        private void bbUser_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            SplashScreenManager.ShowForm(typeof(WaitForm1));
            if (_frmUser == null || _frmUser.IsDisposed)
            {
                _frmUser = new Frm_User();
                _frmUser.MdiParent = this;
                _frmUser.Show();
            }
            else
            {
                _frmUser.Activate();
            }
            SplashScreenManager.CloseForm();
        }

        #endregion



        void IntiChildForm<T>(XtraForm pObject) where T : new()
        {
            SplashScreenManager.ShowForm(typeof(WaitForm1));
            if (pObject == null || pObject.IsDisposed)
            {
                pObject = new T() as XtraForm;
                pObject.MdiParent = this;
                pObject.Show();
            }
            else
            {
                pObject.Activate();
            }
            SplashScreenManager.CloseForm();
        }


        private void barButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            DevExpress.XtraTabbedMdi.XtraMdiTabPage tabmana = xtraTabbedMdiManager1.SelectedPage;

            tabmana.MdiChild.Refresh();
        }

        

        

        

        
























    }
}